<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\AclUser;
use ffhome\frame\controller\BaseController;

class Login extends BaseController
{
    public function wxMini(string $code, string $iv, string $encryptedData, string $parentId)
    {
        $app = getMiniFactory();
        // 使用code换取session_key
        $session = $app->auth->session($code);
        // 解密手机号码
        $decryptedData = $app->encryptor->decryptData($session['session_key'], $iv, $encryptedData);
        $this->json_result(AclUser::loginByMobile($decryptedData['phoneNumber'], $parentId, $session['openid']));
    }

    public function normal(string $account, string $password)
    {
        $info = AclUser::loginByAccount($account, $password);
        if (empty($info)) $this->error(lang('login.passwordFail'));
        $this->json_result($info);
    }
}